using System;
using Sedna.Domain.Orders;
using Iesi.Collections;

namespace Sedna.API.Wrapper
{
    /// <summary>
    /// Wraps information about safekeeping shipping and ownership transfer orders
    /// </summary>
    [Serializable]
    public class InventoryShippingOrderWrapper: InventoryOrderWrapper
    {
        private DateTime shippingDate;
        private String fromCustomerCode;
        private String toPartnerCode;
        private ISet lines = new HashedSet();

        #region Properties

        public DateTime ShippingDate
        {
            get { return shippingDate; }
        }

        public string FromCustomerCode
        {
            get { return fromCustomerCode; }
        }

        public string ToPartnerCode
        {
            get { return toPartnerCode; }
        }

        public ISet Lines
        {
            get { return new HashedSet(lines); }
        }

        #endregion

        public InventoryShippingOrderWrapper(Order order)
            : base(order)
        {
            flag = "Safekeeping Shipment order";
        }

        protected override void InitCustom(Order order)
        {
            if (order is InventoryShippingOrder)
            {
                shippingDate = ((InventoryShippingOrder)order).ShippingDate.Value;

                fromCustomerCode = ((InventoryShippingOrder)order).FromCustomer.Code;

                toPartnerCode = ((InventoryShippingOrder)order).ToPartner.Code;


                foreach (InventoryOrderLine ol in ((InventoryShippingOrder)order).Lines)
                {
                    InventoryOrderLineWrapper lineWrapper = new InventoryOrderLineWrapper(ol);
                    lines.Add(lineWrapper);
                }
            }
            else if (order is InventoryOwnershipTransferOrder)
            {
                shippingDate = ((InventoryOwnershipTransferOrder)order).TransferDate.Value;

                fromCustomerCode = ((InventoryOwnershipTransferOrder)order).FromCustomer.Code;

                toPartnerCode = ((InventoryOwnershipTransferOrder)order).ToCustomer.Code;

                foreach (InventoryOrderLine ol in ((InventoryOwnershipTransferOrder)order).Lines)
                {
                    InventoryOrderLineWrapper lineWrapper = new InventoryOrderLineWrapper(ol);
                    lines.Add(lineWrapper);
                }
            }
        }
    }
}
